#include "longCommand.h"


void *pthread_longcommand(void *arg){
      thread_args_t *data = (thread_args_t *)arg;
  
      int sockfd = socket(AF_INET, SOCK_STREAM, 0); 
      struct sockaddr_in addr;
      addr.sin_family = AF_INET;
      char port[] = "20000";
      addr.sin_port = htons(atoi(port));
      addr.sin_addr.s_addr = inet_addr(data->ip);
      int ret = connect(sockfd,(struct sockaddr*)&addr,sizeof(addr));
      ERROR_CHECK(ret,-1,"pthread connect failed:");
      printf("子线程连接服务端成功\n");
//调用gets，puts函数
      free(data);
      return 0;
  }


int longCommandManage(char *ip, int type){
      pthread_t tid;
      thread_args_t *data = (thread_args_t *)calloc(sizeof(thread_args_t), 1);
      data->type = type;
      memcpy(data->ip, ip, strlen(ip)+1);
      pthread_create(&tid, NULL, pthread_longcommand, data);
      return 0;
  }

